package com.itheima.controller;

import com.itheima.entity.Result;
import com.itheima.service.LinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/link")
public class LinkController {
    @Autowired
    private LinkService linkService;

    @PostMapping("/add")
    public Result add(@RequestBody Map<String,Object> linkVO){
        int a = linkService.save(linkVO);
        return new Result("success","添加成功");
    }

    @PostMapping("/delete")
    public Result delete(@RequestBody Map linkVO){
        int a = linkService.delete(linkVO);
        return new Result("success","删除成功");
    }

    @PostMapping("/edit")
    public Result edit(@RequestBody Map linkVO){
        int a = linkService.update(linkVO);
        return new Result("success","更改成功");
    }

    @PostMapping("/getList")
    public Result getList(@RequestBody Map linkVO){
        Map<String,Object> map = linkService.getList(linkVO);
        return new Result("success",map);
    }
    @PostMapping("stick")
    public Result stick(@RequestBody Map linkVO){
        int a = linkService.stick((String)linkVO.get("uid"));
        if (a==2){
            return new Result("fail","已置顶，不可重复置顶");
        }else if (a>0){
            return new Result("success","置顶成功");
        }
        return new Result("fail","置顶失败");
    }
}
